package cc.ilzy.mall.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@EnableKnife4j
@EnableSwagger2WebMvc
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
                                                      // 修改为你实际 Controller 所在的包路径
                                                      .apis(RequestHandlerSelectors.basePackage(
                                                                                           "cc.ilzy.mall.user.controller")
                                                                                   .or(RequestHandlerSelectors.basePackage(
                                                                                           "cc.ilzy.mall.coupon.controller")))
                                                      .paths(PathSelectors.any()).build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("API 文档")
                                   .description("Spring Boot 2.4 整合 Knife4j 基本使用示例")
                                   .version("1.0")
                                   .build();
    }
}
